<template>
  <view>
      <form>
        <xmInfo
    :projectno="dataInfo.projectno"
    :projectname="dataInfo.name"
  ></xmInfo>
         <view class="cu-card">
              <view class="cu-form-group">
                  <view class="title">整改期限</view>
                  <view>{{ dataInfo.endtime  || '' }}</view>
                  <!-- <picker mode="date" :value="dataInfo.endtime"  @change="DateChange('endtime',$event)" :disable="true">
                      <view class="picker"> {{ dataInfo.endtime ? dataInfo.endtime : "请选择整改期限" }}</view>
                  </picker> -->
              </view>
             <view class="cu-form-group ">
                  <view class="title"><text class="cuIcon-kb text-xs text-red"></text>整改内容</view>
                  <view>{{ dataInfo.rectificationcontent }}</view>
              </view>
              <view class="cu-form-group ">
                  <view class="title"><text class="cuIcon-kb text-xs text-red"></text>整改措施</view>
                  <view>{{ dataInfo.rectificationmeasures }}</input></view>
              </view>
              <view class="cu-bar bg-white">
                  <view class="action"><text class="cuIcon-kb text-xs text-red"></text>整改结果</view>
              </view>
              <view class="cu-form-group">
                {{ dataInfo.rectificationresult }}
              </view>
              <view class="cu-form-group">
                  <view class="title"><text class="cuIcon-kb text-xs text-red"></text>整改日期</view>
                  <view>{{ dataInfo.rectificationdate }}</view>
              </view>
              <view class="cu-form-group" style="min-height: 0;"></view>

              <view class="cu-bar bg-white">
                  <view class="action"><text class="cuIcon-kb text-xs text-red"></text>整改图片</view>
              </view>
              <view class="cu-bar bg-white ">
                  <js-uploadfile v-model="dataInfo.dataMap" :biz-key="dataInfo.id" uploadType='all' biz-type="rectList_file"             
                  :deletable="false" 
                  customBtn="false" 
                  ></js-uploadfile>
              </view>
        </view>

        <view>
          <view class="cu-card">
            <view class="cu-form-group ">
                <view class="title"><text class="cuIcon-favorfill text-xs text-red"></text>验收结果</view>
                <view>
                  <!-- <switch :checked="dataInfo.checkresult == '合格'?true:false"  @change="switch1Change"/> -->
                  <js-radio v-model="dataInfo.checkresult" dict-type="zf_check_result"></js-radio>
                </view>
            </view>

            <view class="cu-form-group">
                  <view class="title"><text class="cuIcon-favorfill text-xs text-red"></text>验收时间</view>
                  <picker mode="date" :value="dataInfo.checkdate"  @change="DateChange('checkdate',$event)" >
                      <view class="picker"> {{ dataInfo.checkdate ? dataInfo.checkdate : "请选择验收时间" }}</view>
                  </picker>
            </view>
            <view class="cu-bar bg-white">
                  <view class="action"><text class="cuIcon-favorfill text-xs text-red"></text>验收意见</view>
              </view>
              <view class="cu-form-group">
                <textarea
                  maxlength="-1"
                  v-model="dataInfo.checkopinion"
                  @input="textareaAInput(dataInfo,$event)"
                  placeholder="请输入验收意见"
                ></textarea>
              </view>
            </view>

        </view>

        <view style="height: 200rpx" ></view>
      <view class="btn-group cu-bar foot cu-bar1" >
          <button class="cu-btn bg-blue shadow-blur" @click="save">上传验收结果</button>
          <!-- <button class="cu-btn text-green line-blue shadow">整改验收</button> -->
      </view>
        <!-- v-if="status == vuex_config.zgStatus" -->
      </form>
      
  </view>
</template>
<script>
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import {hasPermission} from '@/common/fire.js'
export default {
components: { xmInfo },
data() {
  return {
    startTime: false, //控制日期显示
    switchA: false,
    modalName: null,
    uploadOptions: {},
    modalNameDetail: null,
    showAddDetail: false,
    dataInfo: {},
    showButton: true,
    flag: hasPermission('proj:zg:pmRectification:edit'),
    status: "",
    projectno: "",
    projectname: "",
  };
},
onLoad(params) {
  let obj = {};
  if (params.id) {
    obj = params;
  } else {
    let item = JSON.parse(params.item);
    obj = {
      projectno: item.projectno,
      name: item.projectname,
    };
    this.projectno = item.projectno;
    this.projectname = item.projectname;
  }
  this.status = params.status;

  this.$u.api.zfgs.zgForm(obj).then((res) => {
    this.dataInfo = res.pmRectification;
    this.dataInfo.projectno = this.dataInfo.projectno
      ? this.dataInfo.projectno
      : this.projectno;
    this.dataInfo.name = this.dataInfo.name
      ? this.dataInfo.name
      : this.projectname;
  });

},
methods: {
  textareaAInput(item, e) {
    console.log(item.item.rectificationresult,'item===');
    if (item.rectificationresult == undefined) {
      this.$set(item, "checkopinion", e.detail.value);
    } else {
      this.$set(item, "rectificationresult", e.detail.value);
    }
  },

  save() {
    if (!this.dataInfo.checkresult) {
      this.$u.toast("验收结果必选");
      return;
    }
    if (!this.dataInfo.checkdate) {
      this.$u.toast("验收时间必选");
      return;
    }
    if (!this.dataInfo.checkopinion) {
      this.$u.toast("验收意见必填");
      return;
    }

    if (this.isSubmitting) {
      return;
    } else {
      this.isSubmitting = true;
      try {
        // 去除this.dataInfo.status 属性
        delete this.dataInfo.status;
        this.$u.api.zfgs.pmRectificationUpdateCheck(this.dataInfo).then((res) => {
          if (res.result == "true") {
            this.$u.toast(res.message);
            setTimeout(() => {
              uni.navigateBack({
                delta: 1,
              });
            }, 500);
          } else {
            uni.showModal({
              title: "提示",
              content: res.message,
              showCancel: false,
              success: (res) => {},
            });
          }
        });
      } catch (error) {
        this.$u.toast(error.message);
      } finally {
        this.isSubmitting = false;
      }
    }
  },
  startConfirm(e) {
    this.dataInfo.endtime = e.year + "-" + e.month + "-" + e.day;
  },
  SwitchA(e) {
    // this.switchA = e.detail.value
  },
  // DateChange(e) {
  //   this.date = e.detail.value;
  // },
  DateChange(item, e) {
    console.log(e.detail.value);
    //   this.dataInfo.inspectiondate = e.detail.value;
    //   更改巡检日期响应式
    if (item === "endtime") {
      this.$set(this.dataInfo, "endtime", e.detail.value);
    } else if (item === "rectificationdate") {
      this.$set(this.dataInfo, "rectificationdate", e.detail.value);
    } else if (item === "checkdate") {
      this.$set(this.dataInfo, "checkdate", e.detail.value);
    }
  },
  // textareaAInput(e) {
  //   this.dataInfo.dmark = e.detail.value;
  // },
  addDetail() {
    this.showAddDetail = true;

    this.modalNameDetail = "bottomModal";

    console.log(this.modalNameDetail);
  },
  modalNameDetailEmit(e) {
    this.modalNameDetail = e;
  },

  ViewImage(imageList, e) {
    uni.previewImage({
      urls: imageList,
      current: e.currentTarget.dataset.url,
    });
  },
  DelImg(e) {
    uni.showModal({
      title: "",
      content: "确定要删除吗？",
      cancelText: "取消",
      confirmText: "确认",
      success: (res) => {
        if (res.confirm) {
          this.$delete(
            this.dataInfo.dImageListst,
            e.currentTarget.dataset.index
          );
        }
      },
    });
  },
  ChooseImage() {
    uni.chooseImage({
      count: 4, //默认9
      sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
      sourceType: ["album"], //从相册选择
      success: (res) => {
        if (this.dataInfo.finishImgList.length != 0) {
          this.dataInfo.finishImgList = this.dataInfo.finishImgList.concat(
            res.tempFilePaths
          );
        } else {
          this.dataInfo.finishImgList = res.tempFilePaths;
        }

        console.log(this.dataInfo, "this.dataInfo");
        this.$u.toast("上传成功");
      },
    });
  },
},
};
</script>
<style lang="scss" scoped>
.pre {
// 空格或者换行符换行
white-space: pre-wrap;
}
/deep/.u-input__input.data-v-460c1d26 {
text-align: right !important;
}
.action {
color: #303133;
}
.title {
flex-shrink: 0;
}
.text-sl {
font-size: 22px !important;
}
.cu-bar1 {
min-height: 80px;
}
.cu-btn {
font-size: 16px;
height: 40px;
}
.foot {
z-index: 997;
background: #fff;
}
.green {
color: green;
}
.input-align {
text-align: right;
}
::v-deep .u-input__input {
text-align: right;
}
.text-xs {
font-size: 18rpx !important;
}
.cuIcon-kb::before {
    // content 为空白
    display: inline-block;
    content: ' ';
    width: 18rpx;
    height: 100%;
    
}
</style>